﻿@{
    ViewBag.Title = ViewData["Action"].ToString() + " Progress - Project Management System";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>@ViewData["Action"].ToString() Progress</h2>
<form id="form" action="" method="post" enctype="multipart/form-data">
<input type="hidden" id="GroupID" name="GroupID" value="@ViewData["GroupID"]" />
<input type="hidden" id="Action" name="Action" value="@ViewData["Action"]" />
<input type="hidden" id="UserID" name="UserID" value="@PMS.Utilities.Utility.UserID" />
<input type="hidden" id="ProjectOwnerID" name="ProjectOwnerID" value="@ViewData["ProjectOwnerID"]" />
<input type="hidden" id="CurUser"  value="@PMS.Utilities.Utility.UserID" />
@{ if (TempData["Message"] != null)
   {
    <div class="notification png_bg" id="messageBox">
        <a href="#" class="close">
            <img src="../../Content/images/icons/cross_grey_small.png" title="Close this notification"
                alt="close" /></a>
        <div>
            @TempData["Message"].ToString()
        </div>
    </div>
   }
}
<div class="content-box column-left " id="Overview" style="width: 100%">
    <!-- From Content Box -->
    <div class="content-box-header">
        <h3>
            Overview
        </h3>
        <div class="clear">
        </div>
    </div>
    <!-- To .content-box-header -->
    <div class="content-box-content">
        <fieldset>
            <div>
                <p>
                    <label class="width12 floatLeft">
                        Completed Task:</label>
                    @(ViewData["Task"].ToString() + " / " + Model.Count)
                </p>
                <p>
                    <label class="width12 floatLeft">
                        Percent:</label>
                    @((ViewData["Percent"].ToString() == string.Empty ? "0" : ViewData["Percent"].ToString()) + "%")
                </p>
                <p>
                    <label class="width12 floatLeft">
                        Total Mark:</label>
                    @((ViewData["Total"].ToString() == string.Empty ? "0" : ViewData["Total"].ToString()))
                </p>
            </div>
        </fieldset>
    </div>
</div>
<br clear="all" />
@{
    for (int count = 0; count < Model.Count; count++)
    {
        bool hide = true;
        string strID = "Mark" + Model[count].ScheduleStatementID;
        if (Model[count].FromDate <= DateTime.Today && Model[count].ToDate >= DateTime.Today)
        {
            hide = false;
        }
    <div class="content-box column-left @(hide ? "closed-box" : "")" id="Progress" style="width:100%;float:left">
        <!-- From Content Box -->
        <div class="content-box-header">
            <h3>@(Model[count].FromDate.ToString("dd/MM/yyyy") + " - " + Model[count].ToDate.ToString("dd/MM/yyyy"))
            </h3>
            <div class="clear">
            </div>
        </div>
        <!-- To .content-box-header -->
        <div class="content-box-content">
            <fieldset id="Timelines@(count)">
                <div id="Timeline@(count)" style="width:60%;float:left">
                    <input type="hidden" id="txtScheduleItemID@(Model[count].ScheduleItemID)" name="ScheduleItemID@(Model[count].ScheduleItemID)" value="@Model[count].ScheduleItemID" />
                    <input type="hidden" id="txtScheduleStatementID@(Model[count].ScheduleItemID)" name="ScheduleStatementID@(Model[count].ScheduleItemID)" value="@Model[count].ScheduleStatementID" />
                    <p>
                        <label class="width12 floatLeft">
                            Work:</label>
                        <input type="text" disabled="disabled" id="txtWork@(Model[count].ScheduleItemID)" name="Work@(Model[count].ScheduleItemID)" class="width20 input-inline text-input medium-input" value="@Model[count].Work"/>
                    </p>
                    <div class="childCol">
                        <p>
                            <label class="width12 floatLeft">
                                Percent:</label>
                            <input type="text" disabled="disabled" id="txtPercent@(Model[count].ScheduleItemID)" name="Percent@(Model[count].ScheduleItemID)" class="DENumber width20 input-inline text-input" value="@Model[count].Percent"/>
                        </p>
                    </div>
                    <div class="childCol">
                        <p>
                            <label class="width12 floatLeft">
                                Mark:</label>
                            @Html.DropDownList(strID, (SelectList)ViewData["ListMark" + count], new { @class = "DENumber marks width20 input-inline text-input", @onchange = "Mark(" + Model[count].ScheduleStatementID + "," + Model[count].ScheduleItemID + ")" })
                        </p>
                    </div>
                    <br clear="all" />
                    <p>
                        <a href="#" id="FileLink@(Model[count].ScheduleItemID)" onclick="UploadModal('@(Model[count].ScheduleStatementID)','@(Model[count].ScheduleItemID)','@(hide)','@ViewData["DeletePer"]','@ViewData["UploadPer"]')">
                            Files</a> @*| <a href="#" id="CommentLink@(Model[count].ScheduleItemID)" onclick="CommentModal('@(Model[count].ScheduleStatementID)','@(Model[count].ScheduleItemID)')">
                                Comments</a>*@
                    </p>
                </div>
                <div id="listCommentOnload@(Model[count].ScheduleItemID)" style="width:40%;float:left"  >
                </div>
            </fieldset>
        </div>
    </div>
  
    <br clear="all" />
    }
}
</form>
<script type="text/javascript">
    $("#Schedule").addClass("current");
    $("#Progress").addClass("current");
    var pOwnerID = $("#ProjectOwnerID").val();
    var curUserID = $("#CurUser").val();



    if (pOwnerID != curUserID) {
        $(".marks").attr("disabled", "disabled");

    }
    else {
        $(".marks").removeAttr("disabled");
    }
    var groupID = $("#GroupID").val();
    var userID = $("#UserID").val();

    function UploadModal(id, itemID, hide, deleteper,uploadper) {
        
        

        var html = ' <h3>\
                        Files</h3>\
                        <fieldset>\
                        <div id="files"> </div>\
                        <div id="fileuploader"></div>\
                        </fieldset>';
        jQuery.facebox(html);

        $.post('@Url.Action("CheckUserInGroup", "Project")', { GroupID: groupID }, function (data) {
            if (data == false) {
                hide = 'True';
            }
        });

      
        $.post('@Url.Action("GetFileList", "Schedule")', { StatementID: id }, function (data) {
            if (data != null) {
                $.each(data.ListFile, function (index, file) {
                    var body = ' <p id="pFileID' + file.FileID + '">\
                            <a href="' + file.FilePath + '" onclick="">' + file.FileName + ' (' + file.FileSize / 1024 + 'KB) </a>'
                    if (hide == 'False' && deleteper == 'True') {
                        body = body + '<a href="#" onclick="RemoveFile(' + file.FileID + ')"> &nbsp;&nbsp;&nbsp;&nbsp; \
                                <img src="../../Content/images/cancel_48.gif" alt="" /></a>';
                    }
                    if(@(PMS.Utilities.Utility.RoleID) == 2)
                    {
                         body = body + '<a href="similar:file'+ file.FileMD5+' " > &nbsp;&nbsp;&nbsp;&nbsp; \
                                Check Similar</a>';
                   }
                    body = body + ' </p>';

                    $("#files").append(body);

                });
            }
        });

        
        if (hide == 'False' && uploadper =='True') {
            var button = $('#fileuploader')[0];
            var uploader = new qq.FileUploader({
                element: button,
                action: '@Url.Action("UploadFile", "Schedule")',
                multiple: true,
                params: { groupID: groupID, scheduleItemID: itemID, schedulegroupid: @ViewData["ScheduleGroupID"] },
                onComplete: function (id, fileName, responseJSON) {
                    //$("#FileLink" + itemID).attr("onclick", "UploadModal('" + responseJSON.statementID + "','" + itemID + "','" + hide + "')");
                    //$("#FileLink" + itemID).bind('click', UploadModal(responseJSON.statementID, itemID, hide));
                    document.getElementById("FileLink" + itemID).onclick = function () { UploadModal(responseJSON.statementID, itemID, hide) };
                    var body = ' <p id="pFileID' + responseJSON.fileInfo.FileID + '">\
                            <a href="' + responseJSON.fileInfo.FilePath + '" onclick="">' + responseJSON.fileInfo.FileName + ' (' + responseJSON.fileInfo.FileSize / 1024 + 'KB) </a>';
                    if (hide == 'False' && deleteper== 'True') {
                        body = body + ' <a href="#" onclick="RemoveFile(' + responseJSON.fileInfo.FileID + ')"> &nbsp;&nbsp;&nbsp;&nbsp; \
                                <img src="../../Content/images/cancel_48.gif" alt="" /></a>';
                    }

                    if(@(PMS.Utilities.Utility.RoleID) == 2){
                        body = body + '<a href="similar:file'+ responseJSON.fileInfo.FileMD5+' " > &nbsp;&nbsp;&nbsp;&nbsp; \
                                Check Similar</a>';
                    }
                    body = body + '</p>';

                    $("#files").append(body);
                }
            });
        }

    }



    function CommentModal(id, itemID) {
        var html = ' <fieldset style="border: 1px solid #CCCCCC;">\
                            <div  style="padding-left: 20px;height:200px;overflow-y:scroll" id="listComment' + itemID + '" ></div>\
                            <br clear="all"/>\
                            <textarea style="float:right"   id="txtComment' + itemID + '" name="Comment"  rows="3"></textarea>\
                            <br clear="all"/>\
                            <input style="float:right" class="button" type="button" id="btnComment' + itemID + '" name="btnComment"  value="Comment"/>\
                        </fieldset>'
        //jQuery.facebox(html);
        
        $("#listCommentOnload" + itemID).append(html);
        $.post('@Url.Action("GetCommentList", "Schedule")', { StatementID: id }, function (data) {
            if (data != null) {
                $.each(data.ListComment, function (index, comment) {
                    var body = '<p id="pComment' + comment.CommentID + '" style=" width: 200px;  word-wrap: break-word;   ">\
                                    <b>\
                                        ' + comment.Owner + ':</b>&nbsp;&nbsp;\
                                    ' + comment.Text + '\
                                    <br clear="all"/>\
                                    <small>' + comment.StrCreatedDate + ' </small>';
                    if (comment.OwnerID == userID) {
                        body = body + ' <a href="#" onclick="RemoveComment(' + comment.CommentID + ')"> &nbsp;&nbsp;&nbsp;&nbsp; \
                                <img src="../../Content/images/cancel_48.gif" alt="" /></a>';
                    }
                    body = body + '</p>';

                    $("#listComment" + itemID).append(body);
                    
                    //kiet scroll bottom after new comment
                    $("#listComment" + itemID).scrollTop($("#listComment" + itemID)[0].scrollHeight);
                });
            }
        });

        $("#btnComment" + itemID).live('click', function () {
            var text = $("#txtComment" + itemID).val();
            $.post('@Url.Action("InsertComment", "Schedule")', { groupID: groupID, scheduleItemID: itemID, text: text, schedulegroupid: @ViewData["ScheduleGroupID"]}, function (data) {
                if (data != null) {
                    //$("#CommentLink" + itemID).bind('click', CommentModal(data.Comment.ScheduleStatementID, itemID));
                    //$("#CommentLink" + itemID).attr("onclick", "UploadModal('" + data.Comment.ScheduleStatementID + "','" + itemID + "')");
                   
                   //kiet 
                    //document.getElementById("CommentLink" + itemID).onclick = function () { CommentModal(data.Comment.ScheduleStatementID, itemID) };

                    var body = '<p id="pComment' + data.Comment.CommentID + '" style=" width: 300px;  word-wrap: break-word;" >\
                                    <b>\
                                        ' + data.Comment.Owner + ':</b>&nbsp;&nbsp;\
                                    ' + data.Comment.Text + '\
                                    <br clear="all"/>\
                                    <small>' + data.Comment.StrCreatedDate + ' </small>';
                    if (data.Comment.OwnerID == userID) {
                        body = body + ' <a href="#" onclick="RemoveComment(' + data.Comment.CommentID + ')"> &nbsp;&nbsp;&nbsp;&nbsp; \
                                <img src="../../Content/images/cancel_48.gif" alt="" /></a>';
                    }
                    body = body + '</p>';

                    $("#listComment" + itemID).append(body);
                    $("#txtComment" + itemID).val('');

                    //kiet scroll bottom after new comment
                    $("#listComment" + itemID).scrollTop($("#listComment" + itemID)[0].scrollHeight);
                }
            });
        });

    }



    function Mark(id, itemID) {

        var mark = $("#Mark" + id).val();
        $.post('@Url.Action("Mark", "Schedule")', { groupID: groupID, scheduleItemID: itemID, mark: mark, schedulegroupid: @ViewData["ScheduleGroupID"] }, function (data) {
            if (data != null) {
                jAlert(data.Message, 'Message');
            }
        });


    }

    function RemoveFile(id) {
        $.post('@Url.Action("DeleteFile", "Schedule")', { fileID: id }, function (data) {
            if (data != null) {
                if (data.Result == 'False') {
                    jAlert(data.Message, 'Message');
                }
                else {
                    $("#pFileID" + id).remove();
                }
            }
        });
    }

  


    function RemoveComment(id) {
        $.post('@Url.Action("DeleteComment", "Schedule")', { commentID: id }, function (data) {
            if (data != null) {
                if (data.Result == 'False') {
                    jAlert(data.Message, 'Message');
                }
                else {
                    $("#pComment" + id).remove();
                }
            }
        });
    }

    
        @foreach (var item in Model)
        {
        <text>
            CommentModal('@(item.ScheduleStatementID)','@(item.ScheduleItemID)');
        </text>
        }
    

</script>
